App({
  onLaunch: function() {
    // 获取系统状态栏信息
    wx.getSystemInfo({
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let custom = wx.getMenuButtonBoundingClientRect();
        this.globalData.Custom = custom;
        this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
      }
    })
    this.getup();
  },
  // version
  getversion: function() {
    let version = wx.getStorageSync('version');
    if (version != this.globalData.version) {
      wx.setStorageSync('version', this.globalData.version);
      wx.navigateTo({
        url: '/pages/self/updateLog'
      })
    }
  },
  // 
  getup: function() {
    // 获取全局唯一的版本更新管理器，用于管理小程序更新。
    let that = this;
    const updateManager = wx.getUpdateManager()
    // 请求完新版本信息的回调
    updateManager.onCheckForUpdate(function(res) {
      console.log(res.hasUpdate)
      if (!res.hasUpdate) {
        that.getversion();
      }
    })
    // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
    updateManager.onUpdateReady(function() {
      wx.showModal({
        title: '提示',
        content: '新的版本已经下载好，点击确认重启',
        showCancel: false,
        success(res) {
          updateManager.applyUpdate()
        }
      })
      console.log('小程序新的版本下载成功');
    })
    // 新的版本下载失败
    updateManager.onUpdateFailed(function() {
      console.log('小程序新的版本下载失败')
    });
  },
  // 网络请求函数封装
  reGetFn: function(urlText, dataArr, hub) {
    let that = this,
      data = '';
    if (hub == "direct")
      data = dataArr
    else
      data = {
        dataArr: dataArr
      }
    return new Promise(function(resolve, reject) {
      wx.request({
        url: urlText,
        method: "GET",
        header: {
          'content-type': "application/x-www-form-urlencoded"
        },
        data,
        complete: function(res) {
          resolve(res);
        },
      })
    });
  },
  // 显示 toast 提示框
  showToast: function(title, icon, image, duration, mask) {
    wx.showToast({
      title,
      icon,
      image,
      duration,
      mask,
    })
  },
  // 显示 loading 提示框
  showLoading: function(title, mask) {
    wx.showLoading({
      title: title,
      mask: mask
    })
  },
  // 隐藏 loading 提示框
  hideLoading: function() {
    wx.hideLoading();
  },
  // 深复制
  coolCopy: function(a) {
    var c = {};
    c = JSON.parse(JSON.stringify(a));
    return c;
  },
  // 全局变量
  globalData: {
    url: "https://hd.qscvip.com/Back.php",
    mapKey: "0cef2b0d5709b8f80c48d5ff4b6c5754",
    selectCity: '珠海',
    version: '2.0.3',
    userInfo: null
  }
})